package com.xingkeduo.remote;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.xingkeduo.dto.AdminDetailDto;
import com.xingkeduo.dto.CraftsmanDTO;
import com.xingkeduo.remote.feign.AdminFeignService;
import com.xingkeduo.utils.ResponseUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


@Service
@Slf4j
public class AdminRemoteService {

    @Resource
    private AdminFeignService adminFeignService;



    public CraftsmanDTO getAdmin(String id) {
        log.info("getAdmin:{}", id);
        JSONObject object = new JSONObject();
        object.put("id", id);
        ResponseUtils<CraftsmanDTO> craftsman = adminFeignService.getCraftsman(object.toString());
        log.info("getAdmin response:{}", craftsman);
        if(craftsman.success()){
            return craftsman.getData();
        }
        return null;
    }


    /**
     * 获取理发师头像和昵称
     *
     * @param id
     * @return
     */
    public List<Object> getAdminInfo(String id) {
        List<Object> obj = new ArrayList<>();
        Map<String, String> map = queryAdminInfo(id);

        if (!map.isEmpty()) {
            obj.add(map);
        }
        return obj;
    }


    public String getAdminImg(String id) {
        CraftsmanDTO admin = getAdmin(id);
        if(admin!=null){
            return admin.getPath();
        }
        return null;
    }


    /**
     * 根据发型师id获取发型师名称
     * @param id
     * @return
     */
    public String getAdminName(String id) {
        CraftsmanDTO admin = getAdmin(id);
        if(admin!=null){
            return admin.getNickName();
        }
        return null;
    }






    /**
     * 根据id 获得发型师详情
     *
     * @param id
     * @return
     */
    public AdminDetailDto craftsman_get(String id) {
        HashMap<Object, Object> map = new HashMap<>();
        map.put("id", id);
        ResponseUtils<AdminDetailDto> adminDetailDtoResponseUtils = adminFeignService.craftsman_get(JSON.toJSONString(map));

        log.info("获得发型师id:{},返回值:{}", id, JSON.toJSONString(adminDetailDtoResponseUtils));

        return adminDetailDtoResponseUtils.getData();
    }




    /**
     * 获取理发师头像和昵称
     *
     * @param id
     * @return
     */
    public  Map<String, String>  queryAdminInfo(String id) {
        Map<String, String> map = new HashMap<>();


        CraftsmanDTO admin = getAdmin(id);
        if(admin!=null){
            map.put("f_avatar", admin.getPath());
            map.put("admin_name", admin.getNickName());
        }

        return map;
    }

//    /**
//     * 小程序获取code
//     *
//     * @param code:
//     * @return : java.lang.String
//     * @author : gaozifeng
//     * @date : 2019/5/8 17:08
//     */
//    public String code(String code) {
//        HashMap<Object, Object> map = new HashMap<>();
//        map.put("html", code);
//        return map.toString();
//    }
//
//    /**
//     * 获取用户信息
//     *
//     * @param consumerPrivateParameterDto:
//     * @return : java.lang.String
//     * @author : gaozifeng
//     * @date : 2019/5/8 17:10
//     */
//    public String get_user_info(ConsumerPrivateParameterDto consumerPrivateParameterDto) {
//        String user_info = adminFeignService.get_user_info(consumerPrivateParameterDto.getEncryptedData(), consumerPrivateParameterDto.getIv(), consumerPrivateParameterDto.getSessionKey(), consumerPrivateParameterDto.getF_user_id(), consumerPrivateParameterDto.getMobile_type());
//        return user_info;
//    }
}
